package com.yellowpage.omc.canal.service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.omc.canal.data.Canal;
import com.yellowpage.omc.canal.dao.CanalDao;

public class CanalServiceImpl extends BaseServiceImpl implements CanalService {
	  private CanalDao canalDao;
	
	  public void setCanalDao(CanalDao canalDao) {
		  this.canalDao = canalDao;
	  }
	
	
	  /* Smooth generate Method */ 
	  public Canal getCanal(Long id){
	      return canalDao.get(id);
	  }
	  
    public List<Canal> getAllCanal(){
        return canalDao.getAll();
    }
    
    public List<Map> queryCanalByPage(Map queryMap, PageRender pageRender) {		
        
		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT a.CANAL_ID , a.ABBR , a.PROMOTION_WAY , a.CONTACT_NAME , a.CONTACT_TEL , a.EMAIL , a.CREATE_USER , a.CREATE_TIME , a.LAST_UPDATE_USER , a.LAST_UPDATE_TIME , a.NOTE , a.ADDRESS , a.NAME , a.TYPE , a.STATUS , a.CODE    FROM OMC_CANAL a WHERE 1=1 ")
				    			.addCondition(" and CANAL_ID = :canalId ")
							    			.addCondition(" and ABBR = :abbr ")
							    			.addCondition(" and PROMOTION_WAY = :promotionWay ")
							    			.addCondition(" and CONTACT_NAME = :contactName ")
							    			.addCondition(" and CONTACT_TEL = :contactTel ")
							    			.addCondition(" and EMAIL = :email ")
							    			.addCondition(" and CREATE_USER = :createUser ")
							    		    .addCondition(" and date_format(CREATE_TIME,'%Y-%m-%d') =  :createTime  ")
		    				    			.addCondition(" and LAST_UPDATE_USER = :lastUpdateUser ")
							    		    .addCondition(" and date_format(LAST_UPDATE_TIME,'%Y-%m-%d') =  :lastUpdateTime  ")
		    				    			.addCondition(" and NOTE = :note ")
							    			.addCondition(" and ADDRESS = :address ")
							    			.addCondition(" and NAME = :name ")
							    			.addCondition(" and TYPE = :type ")
							    			.addCondition(" and STATUS = :status ")
							    			.addCondition(" and CODE = :code ")
							    ; 		    
		    

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}
    
    
    public void saveCanal(Canal canal){
        canalDao.save(canal);
    }
    
	  public void updateCanal(Canal canal){
	      canalDao.update(canal);
	  }
	  
	  public void delete(List deleteList){
	      canalDao.remove(deleteList);
	  }
	  
	  
	 
	
}	